//
//  yuebanxxController.m
//  gangquOASystem
//
//  Created by michael on 2019/1/7.
//  Copyright © 2019年 czd. All rights reserved.
//
#import "GDataDefines.h"

#import "yuebanxxController.h"

@interface yuebanxxController ()
@property(strong,nonatomic)NSMutableArray * contentsArray;

@end

@implementation yuebanxxController
-(NSMutableArray*)contentsArray{
    if (_contentsArray == nil) {
        _contentsArray  = [NSMutableArray array];
    }
    return _contentsArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
        [self requestData];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - Table view data source
-(void)requestData{
                    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unid":self.identifier},@{@"userId":userId}];
    __weak typeof(self) weakSelf = self;
    [HttpTools postWithURL:@"exchImg" arrays:array method:@"lookRecord" success:^(id JSON) {
                        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

     NSData * data = [JSON dataUsingEncoding:NSUTF8StringEncoding];
//         ybxx * detailModel = [[ybxx alloc]init];

    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    //获取根节点（Users）
    GDataXMLElement *rootElement = [doc rootElement];
    //获取根节点下的节点（User）
    NSArray *rootData= [rootElement elementsForName:@"数据"];
    for (GDataXMLElement *subData in rootData) {
        NSArray * tempArray = [subData elementsForName:@"数据要素"];
        for (GDataXMLElement *data in tempArray) {
                 ybxx * detailModel = [[ybxx alloc]init];

            GDataXMLElement *documentElement= [[data elementsForName:@"序号"] objectAtIndex:0];
            detailModel.number = [documentElement stringValue];
             GDataXMLElement *option= [[data elementsForName:@"阅办意见"] objectAtIndex:0];
            detailModel.option = [option stringValue];
             GDataXMLElement *name= [[data elementsForName:@"阅办人"] objectAtIndex:0];
            detailModel.name = [name stringValue];
             GDataXMLElement *time= [[data elementsForName:@"阅办时间"] objectAtIndex:0];
            detailModel.time = [time stringValue];
            
            
            [_contentsArray addObject:detailModel];
         
            
        }
    }
    
    
    
    
    
  
                [weakSelf.tableView reloadData];
     weakSelf.headview.frame = CGRectMake(0, 0, weakSelf.view.bounds.size.width, 46);

    weakSelf.tableView.tableHeaderView = weakSelf.headview;
         } failure:^(NSError *error) {
        
    }];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.contentsArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ybxxTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ybxx" forIndexPath:indexPath];
    ybxx *detailModel = self.contentsArray[indexPath.row];
     cell.number.text = detailModel.number;
            cell.option.text = detailModel.option;
            cell.name.text =detailModel.name;
            cell.time.text = detailModel.time;
              return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 46;
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
